package com.ruoyi.system.service.impl;

import com.ruoyi.system.domain.WarehouseShelfStat;
import com.ruoyi.system.mapper.WarehouseShelfStatMapper;
import com.ruoyi.system.service.WarehouseShelfStatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 库房上架占比统计 Service 实现类
 *
 * @author 你的名字
 */
@Service
public class WarehouseShelfStatServiceImpl implements WarehouseShelfStatService {
    @Autowired
    private WarehouseShelfStatMapper warehouseShelfStatMapper;

    @Override
    public List<WarehouseShelfStat> selectWarehouseShelfStatList(WarehouseShelfStat warehouseShelfStat) {
        return warehouseShelfStatMapper.selectWarehouseShelfStatList(warehouseShelfStat);
    }

    @Override
    public WarehouseShelfStat selectWarehouseShelfStatById(Long id) {
        return warehouseShelfStatMapper.selectWarehouseShelfStatById(id);
    }

    @Override
    public int insertWarehouseShelfStat(WarehouseShelfStat warehouseShelfStat) {
        return warehouseShelfStatMapper.insertWarehouseShelfStat(warehouseShelfStat);
    }

    @Override
    public int updateWarehouseShelfStat(WarehouseShelfStat warehouseShelfStat) {
        return warehouseShelfStatMapper.updateWarehouseShelfStat(warehouseShelfStat);
    }

    @Override
    public int deleteWarehouseShelfStatById(Long id) {
        return warehouseShelfStatMapper.deleteWarehouseShelfStatById(id);
    }

    @Override
    public int deleteWarehouseShelfStatByIds(Long[] ids) {
        return warehouseShelfStatMapper.deleteWarehouseShelfStatByIds(ids);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int batchSaveWarehouseShelfStat(List<WarehouseShelfStat> list) {
        if (list.isEmpty()) {
            return 0; // 空列表直接返回
        }
        // 2. 删除指定库房的旧数据
        warehouseShelfStatMapper.deleteAll();
        // 3. 批量插入新数据
        return warehouseShelfStatMapper.batchInsertWarehouseShelfStat(list);
    }
}